package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author:ahang
 * @create:2022-12-12 13:44
 * @Description:
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerDao customerDao;


    /**
     * 分页查询客户列表
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @Override
    public PageInfo<Customer> getCustList(Integer page, Integer rows, String customerName) {
        PageHelper.startPage(page,rows);
        List<Customer> custList = customerDao.getCustList(customerName);
        return new PageInfo<>(custList);
    }

    /**
     * 添加客户
     * @param customer
     */
    @Override
    public void savaCust(Customer customer) {
        customerDao.savaCust(customer);
    }

    /**
     * 修改客户
     * @param customer
     * @param customerId
     */
    @Override
    public void updataCust(Customer customer, Integer customerId) {
        String customerName = customer.getCustomerName();
        String contacts = customer.getContacts();
        String phoneNumber = customer.getPhoneNumber();
        String address = customer.getAddress();
        String remarks = customer.getRemarks();
        customerDao.updata(customerId,customerName,contacts,phoneNumber,address,remarks);
    }

    /**
     * 删除客户
     * @param ids
     */
    @Override
    public void removeCusts(String ids) {
        customerDao.removeCusts(ids);
    }
}
